package com.tanhua.manager.controller;

import com.tanhua.manager.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/manage")
public class UserController {
    @Autowired
    private UserService userService;
    /**
     * GET/manage/users
     * 用户列表
     */
    @GetMapping("/users")
    public ResponseEntity findUserList(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10")Integer pagesize){
        return userService.findUserList(page,pagesize);
    }

    /**
     * GET/manage/users/:userID
     * 用户基本资料
     */
    @GetMapping("/users/{id}")
    public ResponseEntity findUserById(@PathVariable("id") Long id){
        return userService.findUserById(id);
    }

    /**
     * GET/manage/messages
     * 动态列表
     */
    @GetMapping("/messages")
    public ResponseEntity findPublishList(@RequestParam(defaultValue = "1") Integer page,
                                          @RequestParam(defaultValue = "10")Integer pagesize,
                                          Long uid){
        return userService.findPublishList(page,pagesize,uid);
    }

    /**
     * GET/manage/messages/:id
     * 动态详情
     */
    @GetMapping("/messages/{publishId}")
    public ResponseEntity findPublishById(@PathVariable("publishId")String publishId){
        return userService.findPublishById(publishId);
    }

    /**
     * GET/manage/messages/comments
     * 评论列表
     */
    @GetMapping("/messages/comments")
    public ResponseEntity findCommentList(@RequestParam(defaultValue = "1") int page,
                                          @RequestParam(defaultValue = "10") int pagesize,
                                          String messageID,
                                          String sortProp,
                                          String sortOrder){
        return userService.findCommentList(messageID,page,pagesize);
    }

    /**
     * GET/manage/videos
     * 视频列表
     */
    @GetMapping("/videos")
    public ResponseEntity findVideoList(@RequestParam(defaultValue = "1") int page,
                                        @RequestParam(defaultValue = "10") int pagesize,
                                        Long uid){
        return userService.findVideoList(uid,page,pagesize);
    }


}
